package util;


import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

//@WebListener
//public class SessionListener implements HttpSessionListener {
//	private MySessionContext myc = MySessionContext.getInstance();
//	@Override
//	public void sessionCreated(HttpSessionEvent se) {
//		HttpSession session = se.getSession();  
//        myc.addSession(session); //将你创建的session会话加入到map接口中
//        //下面这句代码用于设置session的声明周期
//        session.setMaxInactiveInterval(3);//以秒为单位，即在没有活动30分钟后，session将失效
//	}
//
//	@Override
//	public void sessionDestroyed(HttpSessionEvent se) {
//		// TODO Auto-generated method stub
//		 HttpSession session = se.getSession();  
//         myc.delSession(session);  //此处用于将你的session对象从map中移除
//	}
//}

public class SessionListener implements HttpSessionListener {

	private MySessionContext myc = MySessionContext.getInstance();  
	
    public SessionListener() {
    }

    public void sessionCreated(HttpSessionEvent httpSessionEvent)  { 
    	HttpSession session = httpSessionEvent.getSession();  
        myc.addSession(session);
    }

    public void sessionDestroyed(HttpSessionEvent httpSessionEvent)  { 
    	HttpSession session = httpSessionEvent.getSession();  
        myc.delSession(session);
    }
	
}
